<?php

Yii::import('application.models._base.BaseKas');
Yii::import('application.components.U');
class Kas extends BaseKas
{
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
    public function beforeValidate()
    {
        $this->tdate = new CDbExpression('NOW()');
        $this->user_id = Yii::app()->user->getId();
        return parent::beforeValidate();
    }
    protected function afterSave()
    {
        parent::afterSave();
        $is_in = $this->total >= 0;
        U::add_bank_trans($is_in ? CASHIN : CASHOUT, $this->kas_id, $this->bank_id, $this->doc_ref, $this->tgl,
            $this->total, $this->user_id);
    }
}